/**
 * 
 */
package com.teamall.web.fpgz.service.impl;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.teamall.core.common.Page;
import com.teamall.core.convert.IArgConversionService;
import com.teamall.core.idproduce.ISequenceGenerator;
import com.teamall.framework.exception.BaseAppException;
import com.teamall.framework.log.LogManager;
import com.teamall.framework.util.Utils;
import com.teamall.web.fpgz.db.arg.CodeFamilyInfoArg;
import com.teamall.web.fpgz.db.arg.CodeFamilyInfoArg.CodeFamilyInfoCriteria;
import com.teamall.web.fpgz.db.dao.CodeFamilyInfoDao;
import com.teamall.web.fpgz.db.po.CodeFamilyInfoPO;
import com.teamall.web.fpgz.service.ICodeFamilyInfoService;

/**
 * <Description> <br>
 * 
 * @author codeCreater<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2014年11月11日 <br>
 * @since V1.0<br>
 * @see com.teamall.web.fpgz.service.impl <br>
 */

@Service("codeFamilyInfoService")
public class CodeFamilyInfoServiceImpl implements ICodeFamilyInfoService {

    private static final LogManager logger = LogManager
            .getLogger(CodeFamilyInfoServiceImpl.class);

    @Autowired
    private CodeFamilyInfoDao codeFamilyInfoDao;

    /**
     * 查询条件转换成Arg类的服务接口
     */
    @Resource(name = "defaultArgConversionService")
    private IArgConversionService argConversionService;

    /**
     * 主键生成器
     */
    @Resource(name = "sequenceProcGenerator")
    private ISequenceGenerator sequenceGenerator;

    @Override
    public CodeFamilyInfoPO selectByPrimaryKey(String key)
            throws BaseAppException {
        // ///////
        // TODO 根据业务场景，设置查询条件、数据校验等

        // ///////
        return codeFamilyInfoDao.selectByPrimaryKey(key);
    }

    @Override
    public List<CodeFamilyInfoPO> selectByArg(CodeFamilyInfoPO record)
            throws BaseAppException {
        logger.debug("selectByArg begin...record={0}", record);

        // 第一种方式：自己创建arg，自行设置查询条件及操作符
        CodeFamilyInfoArg arg = new CodeFamilyInfoArg();
        CodeFamilyInfoCriteria criteria = arg.createCriteria();
        if (Utils.notEmpty(record.getVillageId())) {
            criteria.andVillageIdEqualTo(record.getVillageId());
        }
        criteria.andFamilyIdEqualTo(record.getFamilyId());

        return codeFamilyInfoDao.selectByArg(arg);
    }

    @Override
    public Page<CodeFamilyInfoPO> selectByArgAndPage(CodeFamilyInfoPO record,
            Page<CodeFamilyInfoPO> resultPage) throws BaseAppException {
        logger.debug("selectByArgAndPage begin...record={0}", record);

        // 第一种方式：自己创建arg，自行设置查询条件及操作符
        CodeFamilyInfoArg arg = new CodeFamilyInfoArg();
        CodeFamilyInfoCriteria criteria = arg.createCriteria();
        if(Utils.notEmpty(record.getVillageId())){
            criteria.andVillageIdEqualTo(record.getVillageId());
        }
        if (Utils.notEmpty(record.getVillageName())) {
            criteria.andVillageNameLike(record.getVillageName());
        }

        if (Utils.notEmpty(record.getFamilyId())) {
            criteria.andFamilyIdEqualTo(record.getFamilyId());
        }

        if (Utils.notEmpty(record.getPersonName())) {
            criteria.andPersonNameLike(record.getPersonName());
        }
        if(Utils.notEmpty(record.getAidMainStaff())){
            criteria.andAidMainStaffEqualTo(record.getAidMainStaff());
        }
        resultPage = codeFamilyInfoDao.selectByArgAndPage(arg, resultPage);

        return resultPage;
    }

}
